package com.lineng.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lineng.dao.RecommendMapper;
import com.lineng.pojo.Recommend;
import com.lineng.service.RecommendService;
import com.lineng.util.UrlUtil;
import com.lineng.util.VerificationUtil;

@Service
public class RecommendServiceImpl implements RecommendService {

	@Autowired
	RecommendMapper recommendMapper;

	@Autowired
	private HttpServletRequest request;

	public List<Recommend> getRecommend() {

		return recommendMapper.selectByExample(null);
	}

	public int updateRecommend(Recommend recommend) {
		if (VerificationUtil.verification(request) == 1) {
			if (recommend.getUrl().startsWith("http")) {
				return recommendMapper.updateByPrimaryKeySelective(recommend);
			} else {
				recommend.setUrl(UrlUtil.url(recommend.getUrl()));
				return recommendMapper.updateByPrimaryKeySelective(recommend);
			}
		}
		return 0;

	}

}
